package org.dashboard.security;

import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;

/**
 * Copyright © 2018. All rights reserved.
 *
 * @Author: FreezeSoul
 * @CreateDate: 2018/4/13 10:32
 * @Description:
 * @Version: V1.0
 */
public final class JwtUserFactory {

    private JwtUserFactory() {
    }

    /**
     * Create jwt user.
     *
     * @param userId                the user id
     * @param userName              the user name
     * @param password              the password
     * @param authorities           the authorities
     * @param enable                the enable
     * @param lastPasswordResetDate the last password reset date
     * @return the jwt user
     */
    public static JwtUser create(String userId, String userName, String password, List<String> authorities, boolean enable, Date lastPasswordResetDate) {
        return new JwtUser(userId, userName, password, mapToGrantedAuthorities(authorities), enable, lastPasswordResetDate);
    }

    private static List<GrantedAuthority> mapToGrantedAuthorities(List<String> authorities) {
        return authorities.stream()
                .map(SimpleGrantedAuthority::new)
                .collect(Collectors.toList());
    }
}
